﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace TimeCheque
{

    /// <summary>
    /// Workunit is a start and finish time.
    /// </summary>
    public class WorkUnit
    {

        public int WorkItemID { get; set; }

        /// <summary>
        /// Time the work unit started
        /// </summary>
        public DateTime TimeStart { get; set; }

        /// <summary>
        /// The time at which the workunit completed
        /// </summary>
        public DateTime TimeEnd { get; set; }


        public TimeSpan ElaspedTime
        {
            get 
            {
                TimeSpan ts;
                if (this.TimeEnd == null || this.TimeEnd == DateTime.MinValue)
                {
                    throw new Exception(this.ToString() + " : No TimeEnd set, cannot calculate end time" );
                }
                else
                {
                    ts = TimeEnd - TimeStart;
                }
                return ts;
            }
        
        }

        /// <summary>
        /// User which is working on the task
        /// </summary>
        public User User { get; set; }
    }
}
